Check if logfile can be opend for write

Hey guys,

I've got a problem with checking if my logfile can be opened for write. New loggs are appended everytime the script runs.

If i check it with the 'bool canOpenFile(string pathname, bool forWrite)' function like this:
 

if (!canOpenFile("d:\\CTRS_Import_log.csv", true))
{
    print "cant open file\n"
}

 


the current contents of the file are cleared, but i dont want to lose my loggs.

Is there a posiblity to check this without clearing all contents?

Regards,
Manuel

 


ManuelFelger - Mon Sep 28 08:41:23 EDT 2009

Re: Check if logfile can be opend for write
llandale - Mon Sep 28 16:28:15 EDT 2009

I know I've done this but cannot find it. I'm sure you can 'Stream out = append(NameFile)', which both tells you if you CAN append to the log file, and also opens it for appending.

Using your method, you could always string CurrentContents = readFile(NameFile); then if your canOpenFile works, open the file and save the CurrentContents, then append your new log info.

  • Louie

Re: Check if logfile can be opend for write
ManuelFelger - Fri Oct 02 07:25:17 EDT 2009

Thanks Louie,

It works for me like this:
 

string currentContents = readFile("blabla")
 
if (!canOpenFile("blabla", true))
{
    errorBox "blabla"
        halt
}
 
logfile    = append("blabla")
 
logfile    << currentContents

 


Regards,
Manuel